package cn.com.gas.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;

import cn.com.common.result.DataResult;
import cn.com.gas.entity.GasServerChannelEntity;
import cn.com.gas.service.GasServerChannelService;

/**
 * 分析通道
 *
 * @author shaochangyang
 * @email l2l84o7o5@live.com
 * @date 2024-04-15 20:42:02
 */
@Controller
@RequestMapping("/gas/server/channel/")
public class GasServerChannelController {
	@Autowired
	private GasServerChannelService gasServerChannelService;

	@ApiOperation(value = "新增")
	@PostMapping("gasServerChannel/add")
	@RequiresPermissions("gasServerChannel:add")
	@ResponseBody
	public DataResult add(@RequestBody GasServerChannelEntity gasServerChannel) {
		gasServerChannelService.save(gasServerChannel);
		return DataResult.success();
	}

	@ApiOperation(value = "删除")
	@DeleteMapping("gasServerChannel/delete")
	@RequiresPermissions("gasServerChannel:delete")
	@ResponseBody
	public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids) {
		gasServerChannelService.removeByIds(ids);
		return DataResult.success();
	}

	@ApiOperation(value = "更新")
	@PutMapping("gasServerChannel/update")
	@RequiresPermissions("gasServerChannel:update")
	@ResponseBody
	public DataResult update(@RequestBody GasServerChannelEntity gasServerChannel) {
		gasServerChannelService.updateById(gasServerChannel);
		return DataResult.success();
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@ApiOperation(value = "查询分页数据")
	@PostMapping("/list")
	// @RequiresPermissions("gasServerChannel:list")
	@ResponseBody
	public DataResult findListByPage(@RequestBody GasServerChannelEntity gasServerChannel) {
		Page page = new Page(gasServerChannel.getPage(), gasServerChannel.getLimit());
		LambdaQueryWrapper<GasServerChannelEntity> queryWrapper = Wrappers.lambdaQuery();
		// 查询条件示例
		// queryWrapper.eq(GasServerChannelEntity::getId,
		// gasServerChannel.getId());
		IPage<GasServerChannelEntity> iPage = gasServerChannelService.page(page, queryWrapper);
		return DataResult.success(iPage);
	}

}
